package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.service.ProductSpecService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 商品规格 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/productSpec")
public class ProductSpecController extends BaseController {
    @Autowired
    private ProductSpecService productSpecService;
    @Operation(summary = "获取全部规格")
    @GetMapping("list")
    public TableDataInfo getall(){
        startPage();
        List<ProductSpec> list = productSpecService.getlist();
        return getDataTable(list);

    }
    @Operation(summary = "添加规格")
    @PostMapping
    public AjaxResult post(@RequestBody ProductSpec productSpec){
        productSpec.setCreateBy(SecurityUtils.getUsername());
        productSpecService.save(productSpec);
        return AjaxResult.success();
    }
    @Operation(summary = "删除规格")
    @DeleteMapping("{ids}")
    public AjaxResult delete(@PathVariable("ids") List<Long> ids){
        productSpecService.removeBatchByIds(ids);
        return  AjaxResult.success();
    }
    @Operation(summary = "根据三级分类id查规格参数")
    @GetMapping("/productSpecList/{categoryId}")
    public AjaxResult getspeclist(@PathVariable("categoryId") Long categoryId){
        List<ProductSpec> productSpecList= productSpecService.getspeclist(categoryId);
        return AjaxResult.success(productSpecList);
    }
}
